package com.qf.item1.handler;


import com.baomidou.kaptcha.exception.KaptchaIncorrectException;

import com.qf.item1.ex.CustomerException;
import com.qf.item1.vo.ResultVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @author 刘欣
 * @createTime 2023/1/11 10:38
 * @description
 */
@RestControllerAdvice
@Slf4j
public class ExHandler {

    @ExceptionHandler(CustomerException.class)
    public ResultVo exCustomerHandler(CustomerException customerException) {
        log.debug("用户模块异常customerException={}", customerException.getMsg());
        return ResultVo.error(customerException.getMsg());
    }

    @ExceptionHandler(KaptchaIncorrectException.class)
    public ResultVo KaptchaIncorrectException(KaptchaIncorrectException ex) {
        return ResultVo.error("验证码错误!");
    }

    @ExceptionHandler(Exception.class)
    public ResultVo exHandler(Exception exception) {
        log.debug("用户模块异常customerException={}", exception.getMessage());
        return ResultVo.error(exception.getMessage());
    }
}
